package com.spring.demo.init.db;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;

public class EmbeddedDataSource {

	/**
	 * 供 web 测试
	 * 
	 * @return
	 */
	@Bean(name = "embeddedDataSource")
	public DataSource embeddedDataSource() {
		DataSource dataSource = new EmbeddedDatabaseBuilder()
				.setType(EmbeddedDatabaseType.H2)
				.addScript("classpath:db_schema.sql")
				.addScript("classpath:db_test_data.sql").build();

		return dataSource;
	}
}
